package com.mysteel.cyx.demo.biz.export.bo;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentFontStyle;
import com.alibaba.excel.annotation.write.style.ContentLoopMerge;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.annotation.write.style.HeadFontStyle;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.alibaba.excel.enums.BooleanEnum;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import com.mysteel.cyx.demo.biz.export.WarnOperationEnum;
import com.mysteel.cyx.demo.biz.export.WarnOperationEnumConverter;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.text.DecimalFormat;

@Data
@NoArgsConstructor
@ExcelIgnoreUnannotated
@HeadFontStyle(fontName = "宋体", fontHeightInPoints = 10, bold = BooleanEnum.FALSE)
@ContentFontStyle(fontName = "宋体", fontHeightInPoints = 10)
@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER)
@ContentRowHeight(12)
@HeadRowHeight(18)
@ColumnWidth(15)
public class ComplianceMonitoringErrorBO extends SerialNoBO {
    /*
     * 规则编号
     */
    @ExcelProperty("规则编号")
    private String ruleCode;
    /**
     * 规则说明
     */
    @ExcelProperty("规则说明")
    @ContentStyle(wrapped = BooleanEnum.TRUE)
    @ContentLoopMerge(columnExtend = 2)
    private String ruleSummary;
    @ExcelProperty("规则说明")
    private String ruleSummary1;
    /**
     * 产品名称
     */
    @ExcelProperty("产品名称")
    private String fundName;
    /**
     * 估值账套编号
     */
    @ExcelProperty("估值账套编号")
    private String faAccountNo;
    /**
     * 执行情况
     */
    @ContentFontStyle(fontName = "宋体", fontHeightInPoints = 10, color = 10)
    @ExcelProperty(value = "执行情况", converter = WarnOperationEnumConverter.class)
    private Integer warnOperation;
    /**
     * 实际值 千位分隔符展示，若display_unit单位为%的，需要展示带形位的笹-千
     */
    private BigDecimal calcValue;

    /**
     * 超标值 按千位分隔符展示，若display_unit单位为%的，需要展示带单位的值大/
     */
    private BigDecimal setValue;


    /**
     * 最近一月平均值 按千位分隔符展示，若display_unit单位为%的，需要展示带单位的值
     */
    private BigDecimal avgValue;

    @ExcelProperty("实际值")
    private String calcValueStr;
    @ExcelProperty("违规值")
    private String setValueStr;
    @ExcelProperty("最近一月平均值")
    private String avgValueStr;

    /**
     * 最近一月突破值
     */
    @ExcelProperty("最近一月突破值")
    private BigDecimal violationDayCount;
    /**
     * 连续超标天数
     */
    @ExcelProperty("持+A4:M11续违规天数")
    private Integer continueViolationDays;
    /**
     * 最小超标天数
     */
    @ExcelProperty("最小违规天数")
    private Integer minContinueViolationDays;

    ///**
    // * 超限调整期限
    // */
    //@ExcelProperty("超限调整期限")
    //private Integer adjustableDayCount;
    /**
     * 备注
     */
    @ExcelProperty(value = "备注")
    @ContentLoopMerge(columnExtend = 5)
    private String remarkLong;
    @ExcelProperty(value = "备注")
    private String remarkLong1;
    @ExcelProperty(value = "备注")
    private String remarkLong2;
    @ExcelProperty(value = "备注")
    private String remarkLong3;
    @ExcelProperty(value = "备注")
    private String remarkLong4;


    private Integer displayUnit;

    public void setRuleSummary(String ruleSummary) {
        this.ruleSummary = ruleSummary;
        this.ruleSummary1 = ruleSummary;
    }

    public void setRemarkLong(String remarkLong) {
        this.remarkLong = remarkLong;
        this.remarkLong1 = remarkLong;
        this.remarkLong2 = remarkLong;
        this.remarkLong3 = remarkLong;
        this.remarkLong4 = remarkLong;
    }


    public void setDisplayUnit(Integer displayUnit) {
        this.displayUnit = displayUnit;
        this.calcValueStr = calculateValueStr(getCalcValue(), displayUnit);
        this.setValueStr = calculateValueStr(getSetValue(), displayUnit);
        this.avgValueStr = calculateValueStr(getAvgValue(), displayUnit);

    }

    private String calculateValueStr(BigDecimal value, Integer displayUnit) {
        boolean isZero = value == null || BigDecimal.ZERO.equals(value);
        String formattedString = "0.00";
        if (!isZero) {
            // 创建一个DecimalFormat对象，模式为千分位分隔符且保留原精度
            DecimalFormat decimalFormat = new DecimalFormat("#,###.00");
            // 将BigDecimal转换为格式化的字符串
            formattedString = decimalFormat.format(value);
        }
        if (6 == displayUnit) {
            return formattedString + "%";
        } else {
            return formattedString;
        }
    }

    //private BigDecimal calculateValue(BigDecimal value, Integer displayUnit) {
    //    if (6 == displayUnit) {
    //        return value.multiply(new BigDecimal("0.01"));
    //    } else {
    //        return value;
    //    }
    //}

}
